package org.csc.admin.controller;

import org.csc.admin.entity.User;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/users")
public class UserController extends BaseController {

    /**
     * 获取用户列表
     *
     * @return
     */
    @GetMapping("/userList")
    @Secured("ROLE_ADMIN")
    public Map<String, Object> userList() {
        User u = super.getUser();
        List<User> users = userRepository.findAll();
        logger.info("users: {}", users);
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("users", users);
        map.put("u", u);
        return map;
    }

    @GetMapping("/authorityList")
    public List<String> authorityList() {
        List<String> authentication = getAuthentication();
        return authentication;
    }

}
